﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebPromenadebyenTabeller;
using PromPersonerDB;
using PromArrangementDB;

namespace WebApptest
{
    public partial class WebFormLogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List<Arrangementer> listArrangementer = PromGatewayArrangementer.FindAlleArrangementer();
            foreach (Arrangementer item in listArrangementer)
            {
                var ting = "<table border=\"0\" width=\"820\" cellpadding=\"5\" cellspacing=\"10\" background=\"./images/tablebg.png\" style=\"margin-top: 30px; padding-bottom: 15px;\"><tr><td align=\"center\" width=\"200\"><h1>" + item.Overskrift + "</h1><p align=\"left\">" + item.Beskrivelse + "</p></td></tr></table>";
                var arrangementerhtml = new LiteralControl(ting);
                PHArrangementer.Controls.Add(arrangementerhtml);              
            }        
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string user = tbxEmail.Text;
            string password = tbxPassword.Text;

            Personer loginPerson = PromGatewayPersoner.FindEmail(user);
            int status = loginPerson.status;
            string dbEmail = loginPerson.email;
            string dbPassword = loginPerson.navn; // Password overføres fra FindEmail i "Navn" !!!
            int dblID = loginPerson.lejlighedsID;
         

            if ((dbEmail == user) && (dbPassword == password))
            {
                Session["email"] = tbxEmail.Text; //evt. erstattes af Adgangsniveau når det er med i tabellen
                Session["lejlighedsID"] = dblID;
                Session["status"] = status;
               

                Response.Redirect("WebFormArrangementer.aspx");
            }

        }
    }
}